angular.module('app', [
    'admin'
    , 'header'
    , 'menu'
    , 'security'
    , 'directives.zTree'
    , 'services.rpc' // 统一封装的访问方法
    , 'services.breadcrumbs'
    , 'services.i18nNotifications'
    //, 'services.httpRequestTracker'
    , 'templates.app' // 引入模板控件，该控件由grunt自动生成
    , 'templates.common' // 引入模板控件，由grunt自动生成
    , 'ui.router' // 引入第三方控件
    , 'COMMON_DEFINE' // 引入常量
]);

angular.module('app').config(['$locationProvider', '$stateProvider', '$urlRouterProvider', 'ROOT_STATE_NAME', 
         function ($locationProvider, $stateProvider, $urlRouterProvider, ROOT_STATE_NAME) {

    $stateProvider
        // 加载主页
        .state(ROOT_STATE_NAME, {
            url : '/keter'
            , views : {//gulx:为什么使用after-content? main-content是不是没使用？
            	//gulx:1、xxx-content.tpl.html是否考虑集中放置于某个目录？
            	//gulx:2、[全局]框架的样式、内容、业务逻辑(js)和业务模块的页面是否考虑目录规划、分离？
                'iframeContent@' : { templateUrl : 'after-content.tpl.html' }
            }
        })
        .state('login', {
            url : '/keter/login'
            , views : {
                'iframeContent@' : { templateUrl : 'front-content.tpl.html' }
            }
        });

    $urlRouterProvider.otherwise('/keter');//gulx:可否导向404页面?
}]);

angular.module('app').run(['$rootScope', 'security', '$state', 'breadcrumbs', 
           function($rootScope, security, $state, breadcrumbs) {
    // Get the current user when the application starts
    // (in case they are still logged in from a previous session)
    security.requestCurrentUser().then(function (currentUser) {
        if (!currentUser) { // 如果登陆显示主页
            $state.go('login');
        }
    });
}]);

angular.module('app').constant('I18N.MESSAGES', {
	  'errors.route.changeError':'Route change error',
	  'crud.user.save.success':"A user with id '{{id}}' was saved successfully.",
	  'crud.user.remove.success':"A user with id '{{id}}' was removed successfully.",
	  'crud.user.remove.error':"Something went wrong when removing user with id '{{id}}'.",
	  'crud.user.save.error':"Something went wrong when saving a user...",
	  'crud.project.save.success':"A project with id '{{id}}' was saved successfully.",
	  'crud.project.remove.success':"A project with id '{{id}}' was removed successfully.",
	  'crud.project.save.error':"Something went wrong when saving a project...",
	  'login.reason.notAuthorized':"You do not have the necessary access permissions.  Do you want to login as someone else?",
	  'login.reason.notAuthenticated':"You must be logged in to access this part of the application.",
	  'login.error.invalidCredentials': "Login failed.  Please check your credentials and try again.",
	  'login.error.serverError': "There was a problem with authenticating: {{exception}}."
});

angular.module('app').constant('CHN.MESSAGES', {
	  'login.username':'请输入用户名',
	  'login.password':"请输入密码",
	  'login.title.':"请输入您的登录信息",
	  'login.remember' : '记住我',
	  'login.btn' : '登录',
	  'login.forget' : '忘记我的密码',
	  'login.register' : '我要注册',
	  'login.reason.notAuthorized':"亲，你没有这些权限，要不您换个账号登录试一试吧？",	  
	  'login.reason.notAuthenticated':"亲，您没登录呢，瞎操作啥呢！",	  
	  'login.error.invalidCredentials': "亲，登录失败了，请检查用户名和密码是否正确。",
	  'login.error.serverError': "登录失败，系统出现错误: {{exception}}.",
	  'regist.error.enterPasswordError': '两次输入密码内容不匹配！'
});

angular.module('app').controller('AppCtrl', ['$q', '$log', '$scope', function ($q, $log, $scope) {
	//$scope.haha = 'abc';
	//var pawel = new Person('Oscar', $log);
	//var pizzaPit = new Restaurant($q, $scope);
	//var pizzaDelivered = pizzaPit.takeOrder('Capricciosa');
	//pizzaDelivered.then(pawel.eat('shit'), pawel.beHungry('no'));
	//pizzaPit.problemWithOrder('no Capricciosa, onlyMargherita left');
}]);

